<template>
  <div>
    <!-- 列表 -->
    <sing-table :data="this.$data" :list="list" :selection="false">
      <template v-slot:title="scope">
        <div>
          <div @click="$detail(scope.row.id)" class="table-link">
            {{ scope.row.title }}
          </div>
        </div>
      </template>
    </sing-table>
    <pagination
      @getList="getList"
      :form.sync="form"
      :total="total"
    ></pagination>
    <!-- 详情 -->
    <detail
      v-if="detailVisible"
      :visible.sync="detailVisible"
      :id="id"
    ></detail>
  </div>
</template>

<script>
import Mixin from "@/mixins/list";
import columns from "./columns/index";
import apiCode from "@/api/apiConfig";

export default {
  name: "collection",
  mixins: [Mixin],
  components: {},
  data() {
    return {
      columns, // 列表字段
    };
  },
  created() {
    // 获取列表
    this.getList();
    // 监听列表刷新事件
    this.$on("global:collectionFresh", () => {
      this.getList();
    });
  },
  methods: {
    async getList() {
      this.loading = true;
      let { pageSize = 10, pageNum = 0 } = this.form;
      let result = await this.$get(`api/article/watches`, {
        pageSize,
        pageNum: pageNum - 1,
      });
      this.loading = false;
      if (result && result.code === apiCode.code.success) {
        const { content, totalElements } = result.data;
        this.list = content || [];
        this.total = totalElements || 0;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
